import { useRef } from "react"

function AddShop({ addShop }) {
    const titleInput = useRef()
    const priceInput = useRef()
    return (
        <div>
            <input type="text" ref={titleInput} placeholder="输入商品名称" />
            <input type="number" ref={priceInput} placeholder="输入商品单价" />
            <button onClick={() => {
                const title = titleInput.current.value;
                const price = priceInput.current.value;

                if (!title.trim()) {
                    console.log("商品名稱不能為空")
                    return
                }
                if (!price.trim()) {
                    console.log("商品價格不能為空")
                    return
                }
                let newdata = {
                    id: new Date().getTime(),
                    title,
                    price,
                    amount: 0,
                    totalPrice: 0
                }
                addShop(newdata)
            }}>添加商品</button>
        </div>
    )
}
export default AddShop